
<?php include_once(dirname(__FILE__) . '/../general/head.php'); ?>

<?php include_once(dirname(__FILE__) . '/../general/header.php'); ?>

<?php include_once('left.php'); ?>
<div id="page-wrapper">


    <div class="row">
        <div class="col-lg-12">
            <h1 class="page-header">Kết quả trắc nghiệm</h1>
        </div>
        <!-- /.col-lg-12 -->
    </div>
    <!-- /.row -->
    <div class="row">
        <div class="col-lg-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    Danh sách
                </div>
                <!-- /.panel-heading -->
                <div class="panel-body">
                    <div class="col-lg-12">
                        Supervisor 
                        <select class="form-control display-inline" name="filter-ss" style="width: 200px;">
                            <option value="all">Tất cả</option>
                            <?php foreach ($supervisors as $eachSS) { ?>
                                <option value="<?php echo $eachSS['code']; ?>" <?php echo ($filterSS == $eachSS['code']) ? 'selected="selected"' : ''; ?>><?php echo $eachSS['name']; ?></option>
                            <?php } ?>
                        </select>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        Nhóm
                        <select class="form-control display-inline" name="filter-title" style="width: 100px;">
                            <option value="all">Tất cả</option>
                            <?php
                            foreach ($titles as $key => $value) {
                                ?>
                                <option value="<?php echo $value; ?>" <?php echo ($filterTitle == $value) ? 'selected="selected"' : ''; ?>><?php echo $key; ?></option>
                            <?php } ?>
                        </select>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        Trắc nghiệm
                        <select class="form-control display-inline" name="filter-done" style="width: 150px;">
                            <option value="all" <?php echo ($filterDone == 'all') ? 'selected="selected"' : ''; ?>>Tất cả</option>
                            <option value="done" <?php echo ($filterDone == 'done') ? 'selected="selected"' : ''; ?>>Đã làm bài</option>
                            <option value="not" <?php echo ($filterDone == 'not') ? 'selected="selected"' : ''; ?>>Chưa làm bài</option>
                        </select>
                        <br><br>
                    </div>

                    <div class="col-lg-4">
                        <table class="table table-bordered">
                            <tr><td>Số nhân viên</td><td><?php echo count($rows) ?></td></tr>
                            <?php if ($filterDone == 'all') { ?>

                                <tr><td>Đã làm bài</td><td><?php echo $numberDone ?></td></tr>
                                <tr><td>Chưa làm bài</td><td><?php echo $numberNot ?></td></tr>
                            <?php } ?>
                            <?php if ($filterDone == 'all' || $filterDone == 'done') { ?>
                                <tr><td>Đang được cho làm bài lại</td><td><?php echo $doAgain ?></td></tr>
                            <?php } ?>
                        </table>
                    </div>

                    <div class="col-lg-12">
                        <?php if ($rows == false || count($rows) == 0) { ?>
                            Hiện tại không có kết quả nào!
                            <br>
                        <?php } else { ?>
                            <div class="table-responsive">
                                <table class="table table-striped table-bordered table-hover" id="test-results">
                                    <thead>
                                        <tr>
                                            <th>TL code</th>
                                            <th>SS code</th>
                                            <th>RSM code</th>
                                            <!--<th width="40px">No</th>-->

                                            <th width="90px">Area</th>
                                            <th width="110px">Location</th>
                                            <th width="70px">Mã NV</th>
                                            <th width="50px">Title</th>
                                            <th>Họ và tên</th>

                                            <th>Trắc nghiệm</th>
                                            <th>Thời điểm làm bài</th>
                                            <th>Thời gian</th>
                                            <th>Số điểm</th>
                                            <th>Số lần</th>
                                            <!--<th>Cho phép làm lại </th>-->
                                        </tr>
                                    </thead>
                                    <tbody>

                                        <?php
                                        $i = 1;
                                        foreach ($rows as $row) {
                                            ?>
                                            <tr>
                                                <td><?php echo $row['teamleader_code']; ?></td>
                                                <td><?php echo $row['supervisor_code']; ?></td>
                                                <td><?php echo $row['rsm_code']; ?></td>
                                                <!--<td><?php echo $i; ?></td>-->

                                                <td><?php echo $regionDic[$row['rsm_code']]; ?></td>
                                                <td><?php echo $row['location']; ?></td>
                                                <td><?php echo $row['code']; ?></td>
                                                <td><?php echo $row['title']; ?></td>
                                                <td><?php echo $row['name']; ?></td>

                                                <td><?php echo $row['testInfo']['quiz_name']; ?></td>
                                                <td><?php echo ($row['testResult']) ? date("Y-m-d H:i:s", $row['testResult']['start_time']) : ''; ?></td>
                                                <td><?php echo ($row['testResult']) ? gmdate("H:i:s", $row['testResult']['time_spent']) : ''; ?></td>
                                                <td><?php echo $row['testResult']['score']; ?></td>
                                                <td><?php echo $row['testResult']['number_of_attempt']; ?></td>
                                                <?php if(false){ ?>
                                                <td>
                                                    <?php
                                                    if ($row['testResult'] && $row['testResult']['number_of_attempt'] > 0) {
                                                        if ($row['credit'] > 0) {
                                                            ?>
                                                            Đang được làm lại
                                                        <?php } else { ?>
                                                            <form method="post" action="<?php echo site_url(get_folder($loggedUser['title']) . '/test_results/do_again'); ?>" onsubmit="return confirm('Bạn có chắc là muốn cho <?php echo $row['name']; ?> làm lại?');">
                                                                <input type="hidden" name="user_id" value="<?php echo $row['id']; ?>" />
                                                                <input type="hidden" name="quid" value="<?php echo $row['testInfo']['quid']; ?>" />
                                                                <input type="submit" value="Cho làm lại" class="btn btn-primary" />
                                                            </form>
                                                            <?php
                                                        }
                                                    }
                                                    ?>
                                                </td>
                                                <?php } ?>

                                            </tr>

                                            <?php
                                            $i++;
                                        }
                                        ?>

                                    </tbody>
                                </table>
                                <br>
                                <!--<a href="<?php echo site_url(get_folder($loggedUser['title']) . '/users/add_new'); ?>"> <img src="<?php echo base_url(); ?>images/plus.png" title="Thêm nhân viên mới"> Thêm nhân viên mới</a>-->
                            </div>
                        <?php } ?>
                    </div>

                </div>
                <!-- /.panel-body -->
            </div>
        </div>
    </div>


</div>
<script type="text/javascript">
    function search()
    {
        var ss_code = "";
        var title = "";
        var done = "";

        $("select[name=filter-ss] option:selected").each(function() {
            ss_code = $(this).val();
        });
        $("select[name=filter-title] option:selected").each(function() {
            title = $(this).val();
        });
        $("select[name=filter-done] option:selected").each(function() {
            done = $(this).val();
        });
        window.location = '<?php echo site_url(get_folder($loggedUser['title']) . '/test_results/index') ?>' + '/' + ss_code + '/' + title + '/' + done;
    }

    $(document).ready(function() {
        var oTable = $('#test-results').dataTable(
                {
                    "iDisplayLength": 50,
                    "scrollX": true,
                    "sScrollX": "120%",
                    //"aaSorting": [[ 3, "desc" ]],
                    "columnDefs": [
                        {
                            "targets": [0],
                            "visible": false,
                            "searchable": false,
                            "orderData": [0, 1]
                        },
                        {
                            "targets": [1],
                            "visible": false,
                            "searchable": false,
                            "orderData": [0, 1]
                        },
                        {
                            "targets": [2],
                            "visible": false,
                            "searchable": false,
                            "orderData": [0, 1]
                        }
                    ]
                });

        $('select[name=filter-ss]').change(function() {
            search();
        });

        $('select[name=filter-title]').change(function() {
            search();
        });

        $('select[name=filter-done]').change(function() {
            //oTable.fnFilter('^$', 9, true, false); //get_column_number('')
            search();
        });
    });


</script>

<?php include_once(dirname(__FILE__) . '/../general/footer.php'); ?>
